function [handles] = AnalysisToHandles(pX,pY,P2d,pxsize,type_img,img_time,rawimages,ODraw,xROI,yROI,expp,cons,handles)



handles.fitparam.xfit1d=pX;
handles.fitparam.yfit1d=pY;
handles.fitparam.fit2d=P2d;

% Give the cloud size as the std deviation in meters
handles.sigma.yfit1d = pY(3)*pxsize;    %1D fits Y cloud size (m)
handles.sigma.xfit1d = pX(3)*pxsize;    %1D fits X cloud size (m)
handles.sigma.yfit2d = P2d(6)*pxsize;    %Y cloud size (m)
handles.sigma.xfit2d = P2d(5)*pxsize;    %X cloud size (m)
% Give the cloud size in pixels
handles.width.yfit1d = pY(3);    %1D fits Y cloud size (px)
handles.width.xfit1d = pX(3);    %1D fits X cloud size (px)
handles.width.yfit2d = P2d(6);    %2D Y cloud size (px)
handles.width.xfit2d = P2d(5);    %2D X cloud size (px)
%Position of cloud in pixels
handles.pos.xfit1d = round(pX(2));
handles.pos.yfit1d = round(pY(2));
handles.pos.xfit2d = round(P2d(3));
handles.pos.yfit2d = round(P2d(4));
%Peak OD
handles.OD.peakfit2d = P2d(2);
handles.OD.peakimage = max(max(ODraw(yROI,xROI)));
handles.OD.meanimage = mean(mean(ODraw(yROI,xROI)));
handles.OD.sumOD = sum(sum(ODraw(yROI,xROI)));

% In case the estimated position of the peak OD is outside of the photo
if min(floor(pY(2))+1) >= 1 && max(floor(pY(2))+1) <= expp.short_px_nb && min(floor(pX(2))+1) >= 1 && max(floor(pX(2))+1) <= expp.long_px_nb
    handles.OD.pkatpos1d = ODraw(floor(pY(2))+1,floor(pX(2))+1);
else
    handles.OD.pkatpos1d = NaN;
end

if min(floor(P2d(4))+1) >= 1 && max(floor(P2d(4))+1) <= expp.short_px_nb && min(floor(P2d(3))+1) >= 1 && max(floor(P2d(3))+1) <= expp.long_px_nb
    handles.OD.pkatpos2d = ODraw(floor(P2d(4))+1,floor(P2d(3))+1);
else
    handles.OD.pkatpos2d = NaN;
end

handles.OD.intODanaly = sum(sum(ODraw(yROI,xROI)))*pxsize^2;

if type_img == 1 % Fluorescence - Estimate number of atoms using camera
    handles.numatoms.xfit1d = NAtomsFluo(expp,cons,img_time,pX(3),pX(1));
    handles.numatoms.yfit1d = NAtomsFluo(expp,cons,img_time,pY(3),pY(1));
    handles.numatoms.fit2d = NAtomsFluo(expp,cons,img_time,P2d(5),P2d(2),P2d(6));
    handles.numatoms.ODint = 0;
    
    %Peak density in cubic meters 1D (needs Natoms to calculated)
    handles.density.peaky1d = handles.numatoms.yfit1d/(2*pi*handles.sigma.xfit1d*handles.sigma.yfit1d)^(3/2);
    handles.density.peakx1d = handles.numatoms.xfit1d/(2*pi*handles.sigma.xfit1d*handles.sigma.yfit1d)^(3/2);
    
    %Peak density in cubic meters 2D
    handles.density.peakfit2d = 0;
    handles.density.peakimage = 0;
    
    %Counts on camera
    handles.counts.pkimage = max(max(rawimages(:,:,1)));
    handles.counts.pkbck = 0;
    handles.counts.pkelec = 0;
elseif type_img == 3 % Absorption
    handles.numatoms.xfit1d = pX(1)*sqrt(2*pi)*handles.sigma.xfit1d*pxsize/AbsCross(0,0);
    handles.numatoms.yfit1d = pY(1)*sqrt(2*pi)*handles.sigma.yfit1d*pxsize/AbsCross(0,0);
    handles.numatoms.ODint = handles.OD.intODanaly/AbsCross(0,0);
    handles.numatoms.fit2d = P2d(2)*2*pi*handles.sigma.xfit2d*handles.sigma.yfit2d/AbsCross(0,0);
    
    %Peak density in cubic meters 1D (needs Natoms to calculated)
    handles.density.peaky1d = handles.numatoms.yfit1d/(2*pi*handles.sigma.xfit1d*handles.sigma.yfit1d)^(3/2);
    handles.density.peakx1d = handles.numatoms.xfit1d/(2*pi*handles.sigma.xfit1d*handles.sigma.yfit1d)^(3/2);
    
    %Peak density in cubic meters 2D
    handles.density.peakfit2d = P2d(2)/(AbsCross(0,0)*sqrt(2*pi)*sqrt(handles.sigma.xfit2d*handles.sigma.yfit2d));
    handles.density.peakimage = handles.OD.peakimage/(AbsCross(0,0)*sqrt(2*pi)*sqrt(handles.sigma.xfit2d*handles.sigma.yfit2d));
    
    %Counts on camera
    handles.counts.pkimage = max(max(rawimages(:,:,1)));
    handles.counts.pkbck = max(max(rawimages(:,:,2)));
    handles.counts.pkelec = max(max(rawimages(:,:,3)));
end
end
